//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2009-01-01
// Contains ...
using LargoCommon.Abstract;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
namespace LargoCommon.Music
{
///
/// Instrument Master.
///
public sealed class OrchestraChecker {
#region Fields
///
/// Singleton variable.
///
private static readonly OrchestraChecker InternalSingleton = new OrchestraChecker();
#endregion
#region Constructors
///
/// Prevents a default instance of the class from being created.
///
private OrchestraChecker()
{
}
#endregion
#region Static properties
///
/// Gets the singleton.
///
///
/// Returns value.
///
public static OrchestraChecker Singleton {
get {
Contract.Ensures(Contract.Result() != null);
if (InternalSingleton == null) {
throw new InvalidOperationException("Singleton Orchestra Checker is null.");
}
return InternalSingleton;
}
}
#endregion
#region Properties
///
/// Gets or sets the melodic instruments.
///
///
/// The melodic instruments.
///
private List MelodicInstruments { get; set; }
#endregion
#region Public static methods
#endregion
#region Public methods
///
/// Corrects the octave for instrument.
///
/// The given tones.
public void CorrectOctavesOfInstrumentedTones(MusicalStrikeCollection givenTones) {
Contract.Requires(givenTones != null);
const int defMinTone = 48;
const int defMaxTone = 104;
foreach (var mt in givenTones) {
var mtone = mt as MusicalStrike;
var melt = mt as MusicalTone;
if (melt == null || melt.IsEmpty) {
continue;
}
var tmi = this.MelodicInstruments[mtone.InstrumentNumber];
var tone = melt.Pitch.SystemAltitude;
int minTone = Math.Max(tmi.MinTone, defMinTone);
int maxTone = Math.Min(tmi.MaxTone, defMaxTone);
while (tone < minTone) {
tone += DefaultValue.HarmonicOrder;
}
while (tone > maxTone) {
tone -= DefaultValue.HarmonicOrder;
}
melt.Pitch.SetAltitude(tone);
}
}
///
/// Loads the melodic instruments.
///
/// The given instruments.
public void SetMelodicInstruments(IList givenInstruments) {
this.MelodicInstruments = (List)givenInstruments;
}
#endregion
}
}